{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f5779fdae7286983",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "# 基础数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "%pip install openai\n",
    "%pip install langchain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "5b900f12d3b6974f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-27T14:41:21.558054Z",
     "start_time": "2024-05-27T14:41:13.218366Z"
    },
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import getpass\n",
    "os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(\"输入openAi-key\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67bf2a488a9e94e1",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## Text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b49be30b2557116",
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "user_text = \"今天星期一，明天星期几？\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a226f873632a23a",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## Message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dc1b81bcec36109f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-27T14:41:33.243823Z",
     "start_time": "2024-05-27T14:41:24.523882Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "AIMessage(content='番茄是非常健康的食物，富含维生素C、维生素K和抗氧化剂。以下是一些建议，帮助你更好地享用番茄：\\n\\n1. 生吃：新鲜的番茄可以直接生吃，作为沙拉的一部分，或者加入三明治或卷饼中。这样可以保留番茄的营养成分。\\n\\n2. 煮熟：番茄也可以煮熟，做成番茄酱、番茄汤或烩菜。煮熟的番茄中的番茄红素更容易吸收。\\n\\n3. 拌炒：将番茄与其他蔬菜一起拌炒，增加膳食纤维和维生素的摄入。\\n\\n4. 制作番茄沙司：将新鲜的番茄、洋葱、辣椒和香料混合在一起，制作出美味的番茄沙司，可以用来搭配蔬菜条或者全麦脆饼。\\n\\n5. 烤番茄：烤番茄可以增加一种特殊的香味，同时也可以使番茄更加软糯，适合用来搭配意大利面或者作为开胃菜。\\n\\n记得多样化食用番茄，以确保获得各种不同的营养素。当然，如果你有任何特殊的饮食限制或者健康问题，建议咨询专业营养师获取个性化的建议。祝你健康！')"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain.chat_models import ChatOpenAI\n",
    "from langchain.schema import HumanMessage,SystemMessage,AIMessage\n",
    "\n",
    "chat = ChatOpenAI(model = \"gpt-3.5-turbo\")\n",
    "\n",
    "chat(\n",
    "    [\n",
    "        #提供背景，告诉AI要做什么\n",
    "        SystemMessage(content=\"你作为一个营养师教我如何吃的健康\"),\n",
    "         #用户的输入消息\n",
    "        HumanMessage(content=\"我喜欢吃番茄我应该如何吃？\")\n",
    "    ]\n",
    ")\n",
    "#打印出来的结果AIMessage，是AI返回的消息\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8e991afd23abe45e",
   "metadata": {
    "collapsed": false
   },
   "source": [
    "## Documents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7efd4ed2e7dbc1d1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-27T14:47:14.035870Z",
     "start_time": "2024-05-27T14:47:14.031868Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Document(page_content='这是文档的内容', metadata={'my_document_id': 234234, 'my_document_source': 'The LangChain Papers', 'my_document_create_time': 1680013019, 'my_special_info': '特殊信息'})"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain.schema import Document\n",
    "\n",
    "Document(\n",
    "    page_content = \"这是文档的内容\",\n",
    "    metadata={\n",
    "           #这里可以对文档的元数据进行定义\n",
    "             'my_document_id' : 234234,\n",
    "             'my_document_source' : \"The LangChain Papers\",\n",
    "             'my_document_create_time' : 1680013019,\n",
    "             'my_special_info':'特殊信息'\n",
    "    }\n",
    ")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a15fbee51b84c0c",
   "metadata": {
    "collapsed": false
   },
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
